import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
    TextInput,
    TouchableOpacity,
    DeviceEventEmitter,
    ScrollView
} from 'react-native';

import Constant from '../Constant/Constant'
import ScreenUtils from '../Utils/ScreenUtils'
import ColorUtils from '../Utils/ColorUtils'
import ToastUtils from '../Utils/ToastUtils'
import HttpUtils from '../Utils/HttpUtils'
import RuleUtils from '../Utils/RuleUtils'
import EncryptUtils from '../Utils/EncryptUtils'
import RouterUtils from '../Utils/RouterUtils'
import StorageUtils from '../Utils/StorageUtils'
import TimeUtils from '../Utils/TimeUtils'

export default class PageTypeLawSelect extends React.Component
{
    static navigationOptions = ({navigation}) => ({
        gesturesEnabled: false,//是否支持滑动返回收拾，iOS默认支持，安卓默认关闭
        headerTitle: '法律条文',
        headerStyle: {
            backgroundColor: ColorUtils.blue,
            height: ScreenUtils.statusBarHeight,
        },
        headerRight: (<Text></Text>),
        headerTintColor: ColorUtils.white,
        headerTitleStyle: {
            fontSize: ScreenUtils.Font_18,
            color: ColorUtils.white,
            fontWeight: 'normal',
            flex: 1,
            alignSelf: 'center',
            textAlign: 'center',
        }
    });

    constructor(props)
    {
        super(props);
        this.state = {
            categoryTwoCode: this.props.navigation.state.params.categoryTwoCode,
            lawDesc: '',
        };
    }

    componentDidMount()
    {
        RouterUtils.pushRouter('PageTypeLawSelect', this.props.navigation.state.key);
        this.selectLawCategory();
    }

    componentWillUnmount()
    {
        RouterUtils.popRouter('PageTypeLawSelect', this.props.navigation.state.key);
    }

    selectLawCategory()
    {
        try
        {
            var that = this;
            StorageUtils.get('session').then((session) =>
            {
                if (session != '' && session != null)
                {
                    HttpUtils.getJson(Constant.selectLawCategory + '?eventId=' + that.state.categoryTwoCode, session, function (resultcode, data)
                    {
                        console.log(JSON.stringify(data))
                        if (data.records.length == 0)
                        {
                            that.setState({
                                lawDesc: '无查询到对应法律条文'
                            })
                        } else
                        {
                            that.setState({
                                lawDesc: data.records[0].lawContent
                            })
                        }
                    }, function (resultcode, reason)
                    {
                        ToastUtils.toastShortBottom('错误码:' + resultcode + ',错误原因:' + reason);
                    });
                }
            });
        }
        catch (error)
        {
            ToastUtils.toastShortBottom(error);
        }
    }

    callBack(name)
    {
        this.props.navigation.state.params.callback(name)
        this.props.navigation.goBack();
    }

    render()
    {
        return (
            <ScrollView style={styles.container}>
                <View style={{padding: 16}}>
                    <Text style={{fontSize: ScreenUtils.Font_16, color: ColorUtils.black}}>{this.state.lawDesc}</Text>
                </View>
            </ScrollView>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: ColorUtils.white,
    },
});


